import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MainPanel extends JPanel implements
 MouseListener {

	private Image title, gameStart, end = null;
	
	Rectangle rect;
	

	public MainPanel() {
		initUI();
	}

	private void initUI() {
		//setLayout(null);
		setSize(Constants.SCREEN_WIDTH, Constants.SCREEN_HEGHT);
		try {
		URL ur1 = getClass().getResource("title.png");
		 
			Image image = ImageIO.read(ur1);
			title = image.getScaledInstance(Constants.SCREEN_WIDTH, Constants.SCREEN_HEGHT,
					Image.SCALE_SMOOTH);
			
			ur1 = getClass().getResource("gameStart.png");
			 
//			  image = ImageIO.read(ur1);
//			gameStart = image.getScaledInstance(Constants.SCREEN_WIDTH/6, Constants.SCREEN_HEGHT/6,
//					Image.SCALE_SMOOTH);
			  gameStart = ImageIO.read(ur1);
			
			rect =new Rectangle(gameStart.getWidth(null), gameStart.getHeight(null));
		
		
		} catch (IOException e) {
			
			e.printStackTrace();
		}

		//validate();//콤퍼넌트를 변경시에만 된
		// repaint();//아니..이거 없애도 메인이미지 나오네..
		 
//		 JButton button = new JButton("start");
//		 button.setSize(150, 100);
//			button.setLocation((Constants.SCREEN_WIDTH-button.getWidth())/2,
//					(Constants.SCREEN_HEGHT-button.getHeight())/2);
//		// button = gameStart
//		 button.addActionListener(this);
//		 validate();//콤퍼넌트를 변경시에만 된다
//			add(button);
		addMouseListener(this);
		rect.x = (Constants.SCREEN_WIDTH-gameStart.getWidth(null))/2;
		rect.y = Constants.SCREEN_HEGHT/2;
	}
	
			
		

	@Override
	public void paint(Graphics g) {//g가 가상그림

		super.paint(g);
		//g = title.getGraphics();//Graphics g인자로 바로 넘어오기때문에 안해도 됨
		g.drawImage(title, 0, 0, null);
		g.drawImage(gameStart, rect.x, rect.y, null);
		
	}
	@Override
	public void mouseClicked(MouseEvent e) {
	}
	@Override
	public void mousePressed(MouseEvent e) {
		if (e.getX() == getArea().getX() &&  e.getY() == getArea().getY()) {
		MainScreen screen = new MainScreen();
		screen.setFocusable(true);
		screen.setSize(Constants.SCREEN_WIDTH, Constants.SCREEN_HEGHT);
		getParent().add(screen);
		getParent().remove(screen);
		// TODO Auto-generated method stub
		}	
	}
	@Override
	public void mouseReleased(MouseEvent e) {
	}
	@Override
	public void mouseEntered(MouseEvent e) {	
	}
	@Override
	public void mouseExited(MouseEvent e) {
	}
	


}
